/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// const BigNumber = require('./bignumber') 
import BigNumber from './bignumber' 
 
const BASE_COUNT=100000
const LONG_COUNT=1000000
 
 
/* sqrt  */
function sqrt_Test_01(){   
    try {   
        BigNumber.config({ DECIMAL_PLACES: 36, ROUNDING_MODE: 1 });
        let result 
        let big = new BigNumber('47906644514058120040043799772367208.9448736248559332241111111111111')
        let startTime = Date.now()
        for (let i=0;i<1000;i++) {
            result = big.sqrt()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_sqrt(PLACES_36): " + time +" ms") 
        areEqual('218875865535828595.704079834928718536449349620686728272',result.valueOf())

        // print(result)  
    } catch (err) {
        // print('squareRoot test failed') 
        throw('error ' + err)  
    }
}
/* sqrt  */
function sqrt_Test_02(){   
    try {    
        BigNumber.config({ DECIMAL_PLACES: 73, ROUNDING_MODE: 4 });
        let result 
        let big = new BigNumber('47906644514058120040043799772367208.9448736248559332241111111111111')
        let startTime = Date.now()
        for (let i=0;i<1000;i++) {
            result = big.sqrt()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_sqrt(PLACES_73): " + time +" ms") 
        areEqual('218875865535828595.7040798349287185364493496206867282728132812618414882144492054276854395845',result.valueOf())

        // print(result)   
    } catch (err) {
        // print('squareRoot test failed') 
        throw('error ' + err)  
    }
} 
   
/* Absolute value  */
function absoluteValue_Test_01(){  
    try {
        BigNumber.config({EXPONENTIAL_AT: 100});
        let result 
        let big = new BigNumber('-0.00000000000000497898')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.absoluteValue()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_absoluteValue(EXPONENTIAL_100): " + time +" ms") 
        areEqual('0.00000000000000497898',result.toString())

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    } 
}
/* Absolute value  */
function absoluteValue_Test_02(){  
    try {
        BigNumber.config({EXPONENTIAL_AT: 0});
        let result 
        let big = new BigNumber('-0.00000000000000497898')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.absoluteValue()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_absoluteValue(EXPONENTIAL_0): " + time +" ms") 
        areEqual('4.97898e-15',result.toString())

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    } 
}   
 
/* compare  */
function comparedTo_Test_01(){  
    try {
        BigNumber.config({
            DECIMAL_PLACES: 20,
            ROUNDING_MODE: 4,
            RANGE: 1E9,
            EXPONENTIAL_AT: 1E9
        });
        let result 
        let big = new BigNumber('789456152321657498778945615232165749877894561523216574987789456152321657498778945615232165749877894561523216574987789456152321657498778945615232165749877894561523216574987789456152321657498778945615232165749877894561523216574987')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.comparedTo('-78945615232165749870.000789456152321657498700078945615232165749877894561523216574987009')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_comparedTo(DECIMAL_PLACES20): " + time +" ms") 
        areEqual('1',result.toString())

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    } 
} 
/* compare  */
function comparedTo_Test_02(){  
    try {
        BigNumber.config({
            DECIMAL_PLACES: 0,
            ROUNDING_MODE: 1
        });
        let result 
        let big = new BigNumber('789456152321657498778945615232165749877894561523216574987789456152321657498778945615232165749877894561523216574987789456152321657498778945615232165749877894561523216574987789456152321657498778945615232165749877894561523216574987')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.comparedTo('-78945615232165749870.000789456152321657498700078945615232165749877894561523216574987009')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_comparedTo(DECIMAL_PLACES0): " + time +" ms") 
        areEqual('1',result.toString())

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    } 
} 
 
/*  Returns the number of decimal places  */
function decimalPlaces_Test_01(){   
    try { 
        BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 7, RANGE: 1E9, EXPONENTIAL_AT: 1E9 });
        let result 
        let big = new BigNumber('-6717914940586242525.574537480672174624149')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.decimalPlaces(10)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_decimalPlaces(EXPONENTIAL_AT1E9): " + time +" ms") 
        areEqual('-6717914940586242525.5745374807',result.toString())

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
}  
/*  Returns the number of decimal places  */
function decimalPlaces_Test_02(){   
    try { 
        BigNumber.config({ROUNDING_MODE: 1,EXPONENTIAL_AT: 100});
        let result 
        let big = new BigNumber('-6717914940586242525.574537480672174624149')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.decimalPlaces(10)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_decimalPlaces(EXPONENTIAL_AT100): " + time +" ms") 
        areEqual('-6717914940586242525.5745374806',result.toString())

        // print(result)     
    } catch (err) {
        throw('error ' + err)
    }  
}  
 
/* Division function  */
function dividedBy_Test_01(){   
    try { 
        BigNumber.config({ DECIMAL_PLACES: 40, ROUNDING_MODE: 4, RANGE: [-7, 21], EXPONENTIAL_AT: 1E9 });
        let result 
        let big = new BigNumber(1751456)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.dividedBy('6.1915')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_dividedBy(DECIMAL_PLACES40): " + time +" ms") 
        areEqual('282880.7235726399095534200113058224985867721877',result.toString())

        // print(result)        
    } catch (err) {
        throw('error ' + err)
    }  
}  
/* Division function  */
function dividedBy_Test_02(){   
    try { 
        BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 1, RANGE: [-8, 1e9], EXPONENTIAL_AT: 1E9 });
        let result 
        let big = new BigNumber(1751456)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.dividedBy('6.1915')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_dividedBy(DECIMAL_PLACES20): " + time +" ms") 
        areEqual('282880.72357263990955342001',result.toString())

        // print(result)     
    } catch (err) {
        throw('error ' + err)
    }  
}  

/* Divisibility  */
function dividedToIntegerBy_Test_01(){ 
    // print('\nsubtract test') 
    BigNumber.config({ DECIMAL_PLACES: 40, ROUNDING_MODE: 7, RANGE: 1E9, EXPONENTIAL_AT: 20 });
    try {
        let result
        let big = new BigNumber('64651655727943229435811115735289253096959446020560124180.868366968824689352892530969594460205352892530969552892530969594460205352892530969552892530969594460205352892530969552892530969594460205352892530969594460205')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.dividedToIntegerBy('456')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_dividedToIntegerBy(DECIMAL_PLACES40): " + time +" ms") 
        areEqual('1.41779946771805327710112095910722046265261943027544131e+53',result.toString())

        // print(result)     
    } catch (err) {
        throw('error ' + err)
    }  
} 
/* Divisibility  */
function dividedToIntegerBy_Test_02(){ 
    // print('\nsubtract test') 
    BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: 1, RANGE: 1E9, EXPONENTIAL_AT: 0 });
    try {
        let result
        let big = new BigNumber('64651655727943229435811115735289253096959446020560124180.868366968824689352892530969594460205352892530969552892530969594460205352892530969552892530969594460205352892530969552892530969594460205352892530969594460205')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.dividedToIntegerBy('456')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_dividedToIntegerBy(DECIMAL_PLACES0): " + time +" ms") 
        areEqual('1.41779946771805327710112095910722046265261943027544131e+53',result.toString())

        // print(result)      
    } catch (err) {
        throw('error ' + err)
    }  
} 

/* exponent arithmetic */
function pow_Test_01(){   
    try {
        BigNumber.config({ DECIMAL_PLACES: 1000, ROUNDING_MODE: 4, RANGE: 1E9, EXPONENTIAL_AT: 10 });
        let result
        let big = new BigNumber(0.12)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.pow(32)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_pow(DECIMAL_PLACES1000): " + time +" ms") 
        areEqual('3.4182189187166852111368841966125056e-30',result.toString())

        // print(`Test: 2 pow 64\nResult: ${result} `)  
    } catch (err) {
        throw('error ' + err)
    }  
} 
/* exponent arithmetic */
function pow_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: 1, RANGE: 1E9, EXPONENTIAL_AT: 0 });
    try {
        let result
        let big = new BigNumber(0.12)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.pow(32)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_pow(DECIMAL_PLACES0): " + time +" ms") 
        areEqual('3.4182189187166852111368841966125056e-30',result.toString())

        // print(`Test: 2 pow 64\nResult: ${result} `)  
    } catch (err) {
        throw('error ' + err)
    }  
} 
 
/* round numbers  */
function integerValue_Test_01(){  
    BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 7, RANGE: 1E9, EXPONENTIAL_AT: 1E9  });
    try {
        let result
        let big = new BigNumber('3806471925924246437201.71339576511057957')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.integerValue()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_integerValue(ROUNDING_MODE7): " + time +" ms") 
        areEqual('3806471925924246437202',result.toString())

        // print(`Test: '3806471925924246437201.71339576511057957'\nResult: ${result} `)   
    } catch (err) {
        throw('error ' + err)
    }  
} 
/* round numbers  */
function integerValue_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 1, RANGE: 1E9, EXPONENTIAL_AT: 1E9 });
    try {
        let result
        let big = new BigNumber('3806471925924246437201.71339576511057957')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.integerValue()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_integerValue(ROUNDING_MODE1): " + time +" ms") 
        areEqual('3806471925924246437201',result.toString())

        // print(`Test: '3806471925924246437201.71339576511057957'\nResult: ${result} `)   
    } catch (err) {
        throw('error ' + err)
    }  
} 
 
/* it is equal or not  */
function isEqualTo_Test_01(){  
    BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 4, EXPONENTIAL_AT: 1e+9, RANGE: 1e+9});
    try {
        let result
        let big = new BigNumber('-1.2341478963325874e+2')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.eq(-123.41478963325874, 10)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isEqualTo(ROUNDING_MODE4): " + time +" ms") 
        areEqual(true,result)

        // print(result)      
    } catch (err) {
        throw('error ' + err)
    }  
} 
/* it is equal or not  */
function isEqualTo_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 10, ROUNDING_MODE: 1, EXPONENTIAL_AT: 1e+9, RANGE: 1e+9});
    try {
        let result
        let big = new BigNumber('-1.2341478963325874e+2')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.eq(-123.41478963325874, 10)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isEqualTo(ROUNDING_MODE1): " + time +" ms") 
        areEqual(false,result)

        // print(result)      
    } catch (err) {
        throw('error ' + err)
    }  
}  

/*  if it is bigger  */
function isGreaterThan_Test_01(){  
    BigNumber.config({ DECIMAL_PLACES: 20,  ROUNDING_MODE: 7, EXPONENTIAL_AT: 1e+9, RANGE: 1e+9});
    try {
        let result
        let big = new BigNumber(0.9999978974564516946541654651654646845616516565465464654654659879798)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.isGreaterThan(0.9999978974564516)
        }     
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isGreaterThan(ROUNDING_MODE7): " + time +" ms") 
        areEqual(true,result)

        // print(result)    
    } catch (err) {
        throw('error ' + err)
    }  
}  
/*  if it is bigger  */
function isGreaterThan_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: 1, EXPONENTIAL_AT: 1e+9, RANGE: 1e+9 });
    try {
        let result
        let big = new BigNumber(0.9999978974564516946541654651654646845616516565465464654654659879798)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.isGreaterThan(0.9999978974564516)
        }      
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isGreaterThan(ROUNDING_MODE1): " + time +" ms") 
        areEqual(true,result)

        // print(result)    
    } catch (err) {
        throw('error ' + err)
    }  
}  

/* if it is less than  */
function isLessThan_Test_01(){  
    BigNumber.config({ DECIMAL_PLACES: 20,ROUNDING_MODE: 4,EXPONENTIAL_AT: 1e+9,RANGE: 1e+9});
    try {
        let result
        let big = new BigNumber(-0.21546546541654954986798746163546)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.isLessThan(-0.21546546541654952)
        }     
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isLessThan(ROUNDING_MODE4): " + time +" ms") 
        areEqual(true,result)

        // print(result)    
    } catch (err) {
        throw('error ' + err)
    }  
} 
/* if it is less than  */
function isLessThan_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 2,  ROUNDING_MODE: 1, EXPONENTIAL_AT: 1e+9, RANGE: 1e+9 });
    try {
        let result
        let big = new BigNumber(-0.21546546541654954986798746163546)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.isLessThan(-0.21546546541654952)
        }   
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isLessThan(ROUNDING_MODE1): " + time +" ms") 
        areEqual(true,result)

        // print(result)    
    } catch (err) {
        throw('error ' + err)
    }  
} 
 
/* Subtraction function  */
function minus_Test_01(){  
    BigNumber.config( {ROUNDING_MODE: 3} );
    try {
        let result
        let big = new BigNumber(14654891526954561234567891234567891234781456789)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.minus(14654891526954561234567891234567891234781456789)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_minus(ROUNDING_MODE3): " + time +" ms") 
        areEqual('-0',result.valueOf()) 

        // print(result)    
    } catch (err) {
        throw('error ' + err)
    }  
}  
 /* Subtraction function  */
function minus_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 4, RANGE: 1E9, EXPONENTIAL_AT: [-7, 21] }); 
    try {
        let result
        let big = new BigNumber(-0)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.minus(-1)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_minus(ROUNDING_MODE4): " + time +" ms") 
        areEqual('1',result.valueOf()) 

        // print(result)    
    } catch (err) {
        throw('error ' + err)
    }  
}  
 
/* take the remainder  */
function modulo_Test_01(){  
    BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 4,  RANGE: 1E9, EXPONENTIAL_AT: [-7, 21] });
    try {
        let result
        let big = new BigNumber(-9417874656156549854985199599.979848919549489489984899)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.modulo('14855653.01259498941952561651')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_modul(DECIMAL_PLACES20): " + time +" ms") 
        areEqual('-13039741.9044353685891241266',result.toString())
         
        // print(`Test:  -999.99 modulo '3.01'  \nResult: ${result} `)   
    } catch (err) {
        throw('error ' + err)
    }  
} 
/* take the remainder  */
function modulo_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: 1 });
    try {
        let result
        let big = new BigNumber(-9417874656156549854985199599.979848919549489489984899)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.modulo('14855653.01259498941952561651')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_modul(DECIMAL_PLACES0): " + time +" ms") 
        areEqual('-13039741.9044353685891241266',result.toString())
         
        // print(`Test:  -999.99 modulo '3.01'  \nResult: ${result} `)   
    } catch (err) {
        throw('error ' + err)
    }  
} 
 
/* Multiplication  */
function multipliedBy_Test_01(){  
    BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 4, EXPONENTIAL_AT: [-7, 21],  RANGE: 1E9 });
    try {
        let result
        let big = new BigNumber(1)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.multipliedBy('-4578945678942123456746168791613654685798')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_multipliedBy(DECIMAL_PLACES20): " + time +" ms") 
        areEqual('-4.578945678942123456746168791613654685798e+39',result.toString())
         
        // print(`Test:  1 multipliedBy '-45'  \nResult: ${result} `)    
    } catch (err) {
        throw('error ' + err)
    }  
}  
/* Multiplication  */
function multipliedBy_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 0 });
    try {
        let result
        let big = new BigNumber(1)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.multipliedBy('-4578945678942123456746168791613654685798')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_multipliedBy(DECIMAL_PLACES0): " + time +" ms") 
        areEqual('-4.578945678942123456746168791613654685798e+39',result.toString())
         
        // print(`Test:  1 multipliedBy '-45'  \nResult: ${result} `)    
    } catch (err) {
        throw('error ' + err)
    }  
}  

/* Negative value  */
function negated_Test_01(){  
    try {
        let result
        let big = new BigNumber(1789456789852369852147563214789514741223665589545477854123658)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.negated()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_negated(positive): " + time +" ms") 
        areEqual('-1.78945678985237e+60',result.valueOf())
         
        // print(`Test:  1  \nResult: ${result} `)     
    } catch (err) {
        throw('error ' + err)
    }  
}  
/* Negative value  */
function negated_Test_02(){  
    try {
        let result
        let big = new BigNumber(-1789456789852369852147563214789514741223665589545477854123658)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.negated()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_negated(negative): " + time +" ms") 
        areEqual('1.78945678985237e+60',result.valueOf())
         
        // print(`Test:  1  \nResult: ${result} `)     
    } catch (err) {
        throw('error ' + err)
    }  
}  
 
/* plus  */
function plus_Test_01(){  
    BigNumber.config( {ROUNDING_MODE: 3} );
    try {
        let result
        let big = new BigNumber(-1)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.plus(1)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_plus(ROUNDING_MODE3): " + time +" ms") 
        areEqual('-0',result.valueOf())
  
        // print(`Test: 0 plus -0 \nResult: ${result} `)  
    } catch (err) {
        throw('error ' + err)
    }  
} 
/* plus  */
function plus_Test_02(){  
    BigNumber.config( {ROUNDING_MODE: 4} );
    try {
        let result
        let big = new BigNumber(-1)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.plus(1)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_plus(ROUNDING_MODE4): " + time +" ms") 
        areEqual('0',result.valueOf())
         
        // print(`Test: 0 plus -0 \nResult: ${result} `)  
    } catch (err) {
        throw('error ' + err)
    }  
}  
 
/*  Decimal shift  */
function shiftedBy_Test_01(){  
    BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 4, EXPONENTIAL_AT: [-7, 21], RANGE: 1e9, POW_PRECISION: 0});
    try {
        let result
        let big = new BigNumber(1785423534253476547856746)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.shiftedBy(-15)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_shiftedBy(ROUNDING_MODE4): " + time +" ms") 
        areEqual('1785423534.2534765',result.toString())

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
} 
/*  Decimal shift  */
function shiftedBy_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 10,  ROUNDING_MODE: 1, EXPONENTIAL_AT: [-7, 21], RANGE: 1e9, POW_PRECISION: 0 });
    try {
        let result
        let big = new BigNumber(1785423534253476547856746)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.shiftedBy(-15)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_shiftedBy(ROUNDING_MODE1): " + time +" ms") 
        areEqual('1785423534.2534765',result.toString())

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
} 
 
/*  square Root  */
function squareRoot_Test_01(){  
    BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 4, RANGE: 1E9, EXPONENTIAL_AT: 1E9 });
    try {
        let result
        let big = new BigNumber(45612378.1234596784635615654616546516)
        let startTime = Date.now()
        for (let i=0;i<1000;i++) {
            result = big.squareRoot()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_squareRoot(DECIMAL_PLACES20): " + time +" ms") 
        areEqual('6753.69366520718646075555',result.toString())

        // print(result)  
    } catch (err) {
        throw('error ' + err)
    }  
} 
/*  square Root  */
function squareRoot_Test_02(){  
    BigNumber.config({  DECIMAL_PLACES: 10, ROUNDING_MODE: 1, EXPONENTIAL_AT: [-7, 21], RANGE: 1e9, POW_PRECISION: 0});
    try {
        let result
        let big = new BigNumber(45612378.1234596784635615654616546516)
        let startTime = Date.now()
        for (let i=0;i<1000;i++) {
            result = big.squareRoot()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_squareRoot(DECIMAL_PLACES10): " + time +" ms") 
        areEqual('6753.6936652071',result.toString())

        // print(result)  
    } catch (err) {
        throw('error ' + err)
    }  
} 
 
/* scientific notation  */
function toExponential_Test_01(){ 
    BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 4, RANGE: 1E9, EXPONENTIAL_AT: 1E9}); 
    try {
        let result
        let big = new BigNumber(0.1156461654165485811564616541654851115646165416548511156461654165485111564616541654851)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.toExponential()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_toExponential(DECIMAL_PLACES20): " + time +" ms") 
        areEqual('1.1564616541654858e-1',result)

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
} 
/* scientific notation  */
function toExponential_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 1, ROUNDING_MODE: 1, RANGE: 1E9, EXPONENTIAL_AT: 1E9 }); 
    try {
        let result
        let big = new BigNumber(0.1156461654165485811564616541654851115646165416548511156461654165485111564616541654851)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.toExponential()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_toExponential(DECIMAL_PLACES1): " + time +" ms") 
        areEqual('1.1564616541654858e-1',result)

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
} 

/* to fraction  */
function toFraction_Test_01(){  
    BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 4, RANGE: 1E9, EXPONENTIAL_AT: 1E9 });
    try {
        let result
        let big = new BigNumber('43888091018185790119960206581636.911933980295284713291')
        let startTime = Date.now()
        for (let i=0;i<1000;i++) {
            result = big.toFraction('2834067906')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_toFraction(ROUNDING_MODE4): " + time +" ms") 
        areEqual('118224122484187225351526044435841806374099,2693763154',result.toString())
 
        // print(result)     
    } catch (err) {
        throw('error ' + err)
    }  
} 
/* to fraction  */
function toFraction_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 10, ROUNDING_MODE: 1, RANGE: 1E9, EXPONENTIAL_AT: 1E9 });
    try {
        let result
        let big = new BigNumber('43888091018185790119960206581636.911933980295284713291')
        let startTime = Date.now()
        for (let i=0;i<1000;i++) {
            result = big.toFraction('2834067906')
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_toFraction(ROUNDING_MODE1): " + time +" ms") 
        areEqual('118224122484187225351526044435841806374099,2693763154',result.toString())
 
        // print(result)     
    } catch (err) {
        throw('error ' + err)
    }  
} 
 
/* Division function  */
function toPrecision_Test_01(){  
    BigNumber.config({ROUNDING_MODE: 6});
    try {
        let result
        let big = new BigNumber('154532523452345322.341478945641594895e1')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.toPrecision(3)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_toPrecision(ROUNDING_MODE6): " + time +" ms") 
        areEqual('1.55e+18',result.toString())

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
} 
/* Division function  */
function toPrecision_Test_02(){  
    BigNumber.config({ROUNDING_MODE: 1});
    try {
        let result
        let big = new BigNumber('154532523452345322.341478945641594895e1')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.toPrecision(3)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_toPrecision(ROUNDING_MODE1): " + time +" ms") 
        areEqual('1.54e+18',result.toString())

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
} 

/* if it is Zero  */
function isZero_Test_01(){  
    BigNumber.config({ DECIMAL_PLACES: 20, ROUNDING_MODE: 4, EXPONENTIAL_AT: 1e+9, RANGE: 1e+9 });
    try {
        let result
        let big = new BigNumber('-0.112345978941564429345348542634554263424523465')
        let startTime = Date.now()
        for (let i=0;i<LONG_COUNT;i++) {
            result = big.isZero()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isZero(DECIMAL_PLACES20): " + time +" ms") 
        areEqual(false,result)

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
}  
/* if it is Zero  */
function isZero_Test_02(){  
    BigNumber.config({ DECIMAL_PLACES: 0, ROUNDING_MODE: 2, EXPONENTIAL_AT: 1e+9, RANGE: 1e+9 });
    try {
        let result
        let big = new BigNumber('-0.112345978941564429345348542634554263424523465')
        let startTime = Date.now()
        for (let i=0;i<LONG_COUNT;i++) {
            result = big.isZero()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isZero(DECIMAL_PLACES0): " + time +" ms") 
        areEqual(false,result)

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
}  
 
/* Reserved decimal places  */
function precision_Test_01(){  
    BigNumber.config({ ROUNDING_MODE: 0 });
    try {
        let result
        let big = new BigNumber('123456789.12345678912346789')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.precision(26)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_precision(ROUNDING_MODE0): " + time +" ms") 
        areEqual('123456789.12345678912346789',result.valueOf())

        // print(`Test: '123456789.12345678912346789' precision 26 \nResult: ${result} `)  
    } catch (err) {
        throw('error ' + err)
    }  
}  
/* Reserved decimal places  */
function precision_Test_02(){  
    BigNumber.config({ ROUNDING_MODE: 1 });
    try {
        let result
        let big = new BigNumber('123456789.12345678912346789')
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.precision(26)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_precision(ROUNDING_MODE1): " + time +" ms") 
        areEqual('123456789.12345678912346789',result.valueOf())

        // print(`Test: '123456789.12345678912346789' precision 26 \nResult: ${result} `)  
    } catch (err) {
        throw('error ' + err)
    }  
}  

/* if it is an positive number  */
function isPositive_Test_01(){  
    try {
        let result
        let big = new BigNumber('-65465623545234256430.68947356254134413245984781695498431')
        let startTime = Date.now()
        for (let i=0;i<LONG_COUNT;i++) {
            result = big.isPositive()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isPositive(false): " + time +" ms") 
        areEqual(false,result)

        // print(result)  
    } catch (err) {
        throw('error ' + err)
    }  
}
/* if it is an positive number  */
function isPositive_Test_02(){  
    try {
        let result
        let big = new BigNumber('65465623545234256430.68947356254134413245984781695498431')
        let startTime = Date.now()
        for (let i=0;i<LONG_COUNT;i++) {
            result = big.isPositive()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isPositive(true): " + time +" ms") 
        areEqual(true,result)

        // print(result)  
    } catch (err) {
        throw('error ' + err)
    }  
} 
 

/* Reserved decimal place  */
function toFixed_Test_01(){  
    BigNumber.config({  DECIMAL_PLACES: 20, ROUNDING_MODE: 4, RANGE: 1E9, EXPONENTIAL_AT: 1E9 });
    try {
        let result
        let big = new BigNumber(99.951543523452345623454325784576345234512343214326574568567846746745672986)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.toFixed(10)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_toFixed(ROUNDING_MODE4): " + time +" ms") 
        areEqual('99.9515435235',result)

        // print(`Test: 99.9512986 toFixed 1  \nResult: ${result} `)   
    } catch (err) {
        throw('error ' + err)
    }  
}  
/* Reserved decimal place  */
function toFixed_Test_02(){  
    BigNumber.config({ROUNDING_MODE: 0});
    try {
        let result
        let big = new BigNumber(99.951543523452345623454325784576345234512343214326574568567846746745672986)
        let startTime = Date.now()
        for (let i=0;i<BASE_COUNT;i++) {
            result = big.toFixed(10)
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_toFixed(ROUNDING_MODE0): " + time +" ms") 
        areEqual('99.9515435235',result)

        // print(`Test: 99.9512986 toFixed 1  \nResult: ${result} `)   
    } catch (err) {
        throw('error ' + err)
    }  
}  

/* if it is negative  */
function negative_Test_01() {  
    try {
        let result
        let big = new BigNumber('-431243215498749643652.1445824548654565234546245553461523543252341')
        let startTime = Date.now()
        for (let i=0;i<LONG_COUNT;i++) {
            result = big.isNegative()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isNegative(true): " + time +" ms") 
        areEqual(true,result)

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
}  
/* if it is negative  */
function negative_Test_02() {  
    try {
        let result
        let big = new BigNumber('431243215498749643652.1445824548654565234546245553461523543252341')
        let startTime = Date.now()
        for (let i=0;i<LONG_COUNT;i++) {
            result = big.isNegative()
        }  
        let endTime = Date.now()
        let time = endTime - startTime
        print("bignumber_isNegative(false): " + time +" ms") 
        areEqual(false,result)

        // print(result)   
    } catch (err) {
        throw('error ' + err)
    }  
}  

/* Expected results and actual results verification  */
function areEqual(expected, actual) {
    // If expected and actual are both NaN, consider them equal.
    if (expected === actual || expected !== expected && actual !== actual) {
        // print('Success')
    } else {
        let error = 
        '  Failed areEqual test' +
        '  Expected: ' + expected +
        '  Actual:   ' + actual
        ;
        throw(error) 
    }
}
//exponentiatedBy
function test1 (){
    let x = new BigNumber(4.5677);
	let arr = new Array(10)
	let len = arr.length
	let start = Date.now()
	for (let i = 0; i < LONG_COUNT; i++) {
		arr[i % len] = x.exponentiatedBy()
	}
	let end = Date.now()
	 print("bignumber_exponentiatedBy: " + (end - start) + " ms")
	for (let i = 0; i < 10; i++) {
		if (arr[i] == null) {
			 print("test fail")
		}
	}
}

// function print(s){
//     console.log(s);
// }

/*  Benchmark  */
function bignumberRun() {  
   
    sqrt_Test_01()
    sqrt_Test_02()    

    absoluteValue_Test_01()
    absoluteValue_Test_02() 

    comparedTo_Test_01() 
    comparedTo_Test_02() 

    decimalPlaces_Test_01()
    decimalPlaces_Test_02() 

    dividedBy_Test_01()
    dividedBy_Test_02() 

    dividedToIntegerBy_Test_01() 
    dividedToIntegerBy_Test_02() 

    pow_Test_01() 
    pow_Test_02() 

    integerValue_Test_01() 
    integerValue_Test_02() 

    isEqualTo_Test_01() 
    isEqualTo_Test_02() 
    
    isGreaterThan_Test_01() 
    isGreaterThan_Test_02() 

    isLessThan_Test_01() 
    isLessThan_Test_02() 

    minus_Test_01() 
    minus_Test_02() 

    modulo_Test_01() 
    modulo_Test_02() 

    multipliedBy_Test_01() 
    multipliedBy_Test_02() 

    negated_Test_01() 
    negated_Test_02() 

    plus_Test_01() 
    plus_Test_02() 

    shiftedBy_Test_01() 
    shiftedBy_Test_02() 

    squareRoot_Test_01() 
    squareRoot_Test_02() 

    toExponential_Test_01() 
    toExponential_Test_02() 

    toFraction_Test_01() 
    toFraction_Test_02() 

    toPrecision_Test_01() 
    toPrecision_Test_02() 

    isZero_Test_01() 
    isZero_Test_02() 

    precision_Test_01() 
    precision_Test_02() 

    isPositive_Test_01()  
    isPositive_Test_02()  

    toFixed_Test_01() 
    toFixed_Test_02() 

    test1()
    
    negative_Test_01() 
    negative_Test_02()   
}
bignumberRun()